//
//  OSSApi.swift
//  skincare
//
//  Created by whu125 on 2023/5/12.
//

import Moya

enum OSSApi {
    case uploadImage(data: Data, ossPolicy: OssPolicy)
}

extension OSSApi: TargetType {
    var baseURL: URL {
        guard let url = URL(string: "https://fun-skincare.oss-cn-shanghai.aliyuncs.com") else {
            fatalError("Invalid endpoint")
        }
        return url
    }
    
    var path: String {
        return ""
    }
    
    var method: Method {
        return .post
    }
    
    var sampleData: Data {
        return Data()
    }
    
    var task: Task {
        switch self {
        case let .uploadImage(data, ossPolicy):
            //明天再看具体咋写
            return .requestPlain
//            let request = uploadImage(data: data, ossPolicy: ossPolicy)
//            return .uploadMultipart([MultipartFormData(provider: .data(data), name: "file", fileName: "image.png", mimeType: "image/png"), MultipartFormData(provider: .data(request?.httpBody ?? Data()), name: "", fileName: "", mimeType: "")])
        }
    }
    
    var headers: [String : String]? {
        return ["Content-Type": "multipart/form-data"]
    }
}

let oss_Provider = MoyaProvider<OSSApi>()
